const luckyexport = {};
(function () {
    function widthToBang(width) {
        return (width - 5) / 8 + 0.83
    }

    function strToUint8Array(data) {
        var bstr = data
        var n = bstr.length;
        var u8arr = new Uint8Array(n);
        while (n--) {
            u8arr[n] = bstr.charCodeAt(n);
        }
        return u8arr;
    }

    function base64ToBuffer(data) {
        var bstr = atob(data);
        return strToUint8Array(bstr)
    }

    function exportExcelFront(luckysheet, name, callback = () => {
    }, excelType = "office", isprintImg = true) {
        // 1.创建工作簿，可以为工作簿添加属性
        const workbook = new ExcelJS.Workbook()
        let base64 = newbasedata.split(",")[1]
        let buffer = base64ToBuffer(base64)
        workbook.xlsx.load(buffer).then((r) => {

            let sheets = luckysheet.getAllSheets()
            // 2.创建表格，第二个参数可以配置创建什么样的工作表
            let i = 0
            for (const table of sheets) {

                if (table.data.length === 0) return true
                let worksheet;
                if (i == 0) {
                    worksheet = workbook.worksheets[0]
                    worksheet.name = table.name

                    worksheet.getCell("A1").value = ""


                } else {
                    break
                    worksheet = workbook.addWorksheet(table.name)
                }
                // worksheet.properties.defaultColWidth = widthToBang(table.defaultColWidth)
                // worksheet.properties.defaultRowHeight =  parseInt(table.defaultRowHeight * getptToPxRatioByDPI() / 0.6648)
                const merge = (table.config && table.config.merge) || {}        //合并单元格
                const borderInfo = (table.config && table.config.borderInfo) || {}      //边框
                const columnWidth = (table.config && table.config.columnlen) || {}    //列宽
                const rowHeight = (table.config && table.config.rowlen) || {}      //行高
                const frozen = table.frozen || {}       //冻结
                const rowhidden = (table.config && table.config.rowhidden) || {}    //行隐藏
                const colhidden = (table.config && table.config.colhidden) || {}    //列隐藏
                const filterSelect = table.filter_select || {}    //筛选
                const images = table.images || {}   //图片

                const hide = table.hide;    //工作表 sheet 1隐藏
                if (hide === 1) {
                    // 隐藏工作表
                    worksheet.state = 'hidden';
                }
                setStyleAndValue(table.data, worksheet)
                setColumnWidth(columnWidth, worksheet)
                setRowHeight(rowHeight, worksheet, excelType)
                setFrozen(frozen, worksheet)
                setRowHidden(rowhidden, worksheet)
                setColHidden(colhidden, worksheet)
                setFilter(filterSelect, worksheet)
                setBorder(table, worksheet)
                setMerge(merge, worksheet)
                if (isprintImg) { //是否打印图片（签字签章）
                    setImages(table, worksheet, workbook)
                }
                i++

            }

            function saveAs(blob, name) {
                const objectURL = URL.createObjectURL(blob)
                const domElement = document.createElement('a')
                domElement.href = objectURL
                domElement.download = name
                domElement.click()
                URL.revokeObjectURL(objectURL)
            }

            // 4.写入 buffer
            workbook.xlsx.writeBuffer().then(data => {
                callback(data)
                // const blob = new Blob([data], {
                //     type: 'application/vnd.ms-excel;charset=utf-8'
                // })
                // saveAs(blob, `${name}.xlsx`)
            }).catch((e) => {
                console.log(e)
                callback("")
            })
        }).catch((e) => {
            console.log(e)
            callback("")
        });


        //return buffer
    }

    /**
     * 列宽
     * @param columnWidth
     * @param worksheet
     */
    var setColumnWidth = function (columnWidth, worksheet) {
        for (let key in columnWidth) {
            let width = widthToBang(columnWidth[key])   //((columnWidth[key]-5.5) / 7.5)
            worksheet.getColumn(parseInt(key) + 1).width = (width == 0 ? 0.1 : width)
        }
    }

    /**
     * 行高
     * @param rowHeight
     * @param worksheet
     * @param excelType
     */
    var setRowHeight = function (rowHeight, worksheet, excelType) {
        if (excelType == "wps") {
            for (let key in rowHeight) {
                let height = rowHeight[key] * getptToPxRatioByDPI()
                worksheet.getRow(parseInt(key) + 1).height = height * 0.7
            }
        }
        if (excelType == "office" || excelType == undefined) {
            for (let key in rowHeight) {
                let height = rowHeight[key] * getptToPxRatioByDPI()
                worksheet.getRow(parseInt(key) + 1).height = rowHeight[key] // parseInt(height)   //height / 0.6648
            }
        }
    }

    /**
     * 合并单元格
     * @param luckyMerge
     * @param worksheet
     */
    var setMerge = function (luckyMerge = {}, worksheet) {
        const mergearr = Object.values(luckyMerge)
        mergearr.forEach(function (elem) {
            // elem格式：{r: 0, c: 0, rs: 1, cs: 2}
            // 按开始行，开始列，结束行，结束列合并（相当于 K10:M12）
            worksheet.mergeCells(
                elem.r + 1,
                elem.c + 1,
                elem.r + elem.rs,
                elem.c + elem.cs
            )
        })
        // mergearr.forEach(function (elem) {
        //   const startCell = `${createCol(elem.c)}${elem.r + 1}`
        //   const endCell = `${createCol(elem.c + elem.cs - 1)}${elem.r + elem.rs}`
        //   const end_border = worksheet.getCell(`${endCell}`).border
        //   const start_border = worksheet.getCell(`${startCell}`).border
        //   const border = {}
        //   if (start_border) {
        //     border.top = start_border.top
        //     border.left = start_border.left
        //   }
        //   if (end_border) {
        //     border.bottom = end_border.bottom
        //     border.right = end_border.right
        //   }
        //   worksheet.mergeCells(`${startCell}:${endCell}`);
        //   worksheet.getCell(`${startCell}:${endCell}`).border = border
        // })
    }
    const rgb2hex = (r, g, b) => {
        return '#' + byte2Hex(r) + byte2Hex(g) + byte2Hex(b);
    };
    /**
     * 设置边框
     * @param luckyBorderInfo
     * @param worksheet
     */
    var setBorder = function (lucksheetfile, worksheet) {

        if (!lucksheetfile) return;
        const luckyToExcel = {
            style: {
                0: 'none',
                1: 'thin',
                2: 'hair',
                3: 'dotted',
                4: 'dashDot', // 'Dashed',
                5: 'dashDot',
                6: 'dashDotDot',
                7: 'double',
                8: 'medium',
                9: 'mediumDashed',
                10: 'mediumDashDot',
                11: 'mediumDashDotDot',
                12: 'slantDashDot',
                13: 'thick'
            }
        }
        let merges = lucksheetfile.config.merge

        //获取所有的单元格边框的信息
        const borderInfoCompute = getBorderInfo(lucksheetfile);

        for (let x in borderInfoCompute) {
            let border = {};
            let info = borderInfoCompute[x];
            let row = parseInt(x.substr(0, x.indexOf('_')));
            let column = parseInt(x.substr(x.indexOf('_') + 1));
            let mi = null
            if (merges != null) {
                mi = merges[x]
            }

            if (mi != null) {
                //是合并的单元格
                let real_r = mi.r
                let real_c = mi.c
                let last_r = mi.r + mi.rs - 1
                let last_c = mi.c + mi.cs - 1

                if (real_r == row && real_c == column) {
                    //真正的
                    for (let cr = real_r; cr <= last_r; cr++) {
                        for (let cc = real_c; cc <= last_c; cc++) {
                            let cinfo = borderInfoCompute[cr + "_" + cc];
                            if (cinfo != null) {
                                if (cinfo.t != undefined) {
                                    const tcolor = cinfo.t.color.indexOf('rgb') > -1 ? rgb2hex(cinfo.t.color) : cinfo.t.color;
                                    if (border['top'] == null)
                                        border['top'] = {
                                            style: luckyToExcel.style[cinfo.t.style],
                                            color: {argb: tcolor.replace('#', '')}
                                        };
                                }
                                if (cinfo.r != undefined) {
                                    const rcolor = cinfo.r.color.indexOf('rgb') > -1 ? rgb2hex(cinfo.r.color) : cinfo.r.color;
                                    if (border['right'] == null)
                                        border['right'] = {
                                            style: luckyToExcel.style[cinfo.r.style],
                                            color: {argb: rcolor.replace('#', '')}
                                        };
                                }
                                if (cinfo.b != undefined) {
                                    const bcolor = cinfo.b.color.indexOf('rgb') > -1 ? rgb2hex(cinfo.b.color) : cinfo.b.color;
                                    if (border['bottom'] == null)
                                        border['bottom'] = {
                                            style: luckyToExcel.style[cinfo.b.style],
                                            color: {argb: bcolor.replace('#', '')}
                                        };
                                }
                                if (cinfo.l != undefined) {
                                    const lcolor = cinfo.l.color.indexOf('rgb') > -1 ? rgb2hex(cinfo.l.color) : cinfo.l.color;
                                    if (border['left'] == null)
                                        border['left'] = {
                                            style: luckyToExcel.style[cinfo.l.style],
                                            color: {argb: lcolor.replace('#', '')}
                                        };
                                }
                            }
                        }
                    }
                    worksheet.getCell(row + 1, column + 1).border = border;
                }
            } else {
                if (info.t != undefined) {
                    const tcolor = info.t.color.indexOf('rgb') > -1 ? rgb2hex(info.t.color) : info.t.color;
                    border['top'] = {style: luckyToExcel.style[info.t.style], color: {argb: tcolor.replace('#', '')}};
                }
                if (info.r != undefined) {
                    const rcolor = info.r.color.indexOf('rgb') > -1 ? rgb2hex(info.r.color) : info.r.color;
                    border['right'] = {style: luckyToExcel.style[info.r.style], color: {argb: rcolor.replace('#', '')}};
                }
                if (info.b != undefined) {
                    const bcolor = info.b.color.indexOf('rgb') > -1 ? rgb2hex(info.b.color) : info.b.color;
                    border['bottom'] = {
                        style: luckyToExcel.style[info.b.style],
                        color: {argb: bcolor.replace('#', '')}
                    };
                }
                if (info.l != undefined) {
                    const lcolor = info.l.color.indexOf('rgb') > -1 ? rgb2hex(info.l.color) : info.l.color;
                    border['left'] = {style: luckyToExcel.style[info.l.style], color: {argb: lcolor.replace('#', '')}};
                }
                worksheet.getCell(row + 1, column + 1).border = border;
            }
        }
    }

    var getBorderInfo = function (luckysheetfile) {
        let borderInfoCompute = {};
        let cfg = luckysheetfile.config;
        let data = luckysheetfile.data;
        let borderInfo = cfg["borderInfo"];
        //设置需要计算边框的区域
        let dataset_row_st = 0, dataset_row_ed = data.length, dataset_col_st = 0, dataset_col_ed = data[0].length;
        if (borderInfo != null && borderInfo.length > 0) {
            for (let i = 0; i < borderInfo.length; i++) {
                let rangeType = borderInfo[i].rangeType;

                if (rangeType == "range") {
                    let borderType = borderInfo[i].borderType;
                    let borderColor = borderInfo[i].color;
                    let borderStyle = borderInfo[i].style;

                    let borderRange = borderInfo[i].range;

                    for (let j = 0; j < borderRange.length; j++) {
                        let bd_r1 = borderRange[j].row[0], bd_r2 = borderRange[j].row[1];
                        let bd_c1 = borderRange[j].column[0], bd_c2 = borderRange[j].column[1];

                        if (bd_r1 < dataset_row_st) {
                            bd_r1 = dataset_row_st;
                        }

                        if (bd_r2 > dataset_row_ed) {
                            bd_r2 = dataset_row_ed;
                        }

                        if (bd_c1 < dataset_col_st) {
                            bd_c1 = dataset_col_st;
                        }

                        if (bd_c2 > dataset_col_ed) {
                            bd_c2 = dataset_col_ed;
                        }

                        if (borderType == "border-left") {
                            for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) {
                                if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
                                    continue;
                                }

                                if (borderInfoCompute[bd_r + "_" + bd_c1] == null) {
                                    borderInfoCompute[bd_r + "_" + bd_c1] = {};
                                }

                                borderInfoCompute[bd_r + "_" + bd_c1].l = {"color": borderColor, "style": borderStyle};

                                let bd_c_left = bd_c1 - 1;

                                if (bd_c_left >= 0 && borderInfoCompute[bd_r + "_" + bd_c_left]) {
                                    if (data[bd_r] != null && getObjType(data[bd_r][bd_c_left]) == "object" && data[bd_r][bd_c_left].mc != null) {
                                        let cell_left = data[bd_r][bd_c_left];

                                        let mc = cfg["merge"][cell_left.mc.r + "_" + cell_left.mc.c];

                                        if (mc.c + mc.cs - 1 == bd_c_left) {
                                            borderInfoCompute[bd_r + "_" + bd_c_left].r = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                        }
                                    } else {
                                        borderInfoCompute[bd_r + "_" + bd_c_left].r = {
                                            "color": borderColor,
                                            "style": borderStyle
                                        };
                                    }
                                }

                                let mc = cfg["merge"] || {};
                                for (const key in mc) {
                                    let {c, r, cs, rs} = mc[key];
                                    if (bd_c1 <= c + cs - 1 && bd_c1 > c && bd_r >= r && bd_r <= r + rs - 1) {
                                        borderInfoCompute[bd_r + "_" + bd_c1].l = null;
                                    }
                                }
                            }
                        } else if (borderType == "border-right") {
                            for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) {
                                if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
                                    continue;
                                }

                                if (borderInfoCompute[bd_r + "_" + bd_c2] == null) {
                                    borderInfoCompute[bd_r + "_" + bd_c2] = {};
                                }

                                borderInfoCompute[bd_r + "_" + bd_c2].r = {"color": borderColor, "style": borderStyle};

                                let bd_c_right = bd_c2 + 1;

                                if (bd_c_right < data[0].length && borderInfoCompute[bd_r + "_" + bd_c_right]) {
                                    if (data[bd_r] != null && getObjType(data[bd_r][bd_c_right]) == "object" && data[bd_r][bd_c_right].mc != null) {
                                        let cell_right = data[bd_r][bd_c_right];

                                        let mc = cfg["merge"][cell_right.mc.r + "_" + cell_right.mc.c];

                                        if (mc.c == bd_c_right) {
                                            borderInfoCompute[bd_r + "_" + bd_c_right].l = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                        }
                                    } else {
                                        borderInfoCompute[bd_r + "_" + bd_c_right].l = {
                                            "color": borderColor,
                                            "style": borderStyle
                                        };
                                    }
                                }
                                let mc = cfg["merge"] || {};
                                for (const key in mc) {
                                    let {c, r, cs, rs} = mc[key];
                                    if (bd_c2 < c + cs - 1 && bd_c2 >= c && bd_r >= r && bd_r <= r + rs - 1) {
                                        borderInfoCompute[bd_r + "_" + bd_c2].r = null;
                                    }
                                }
                            }
                        } else if (borderType == "border-top") {
                            if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r1] != null) {
                                continue;
                            }

                            for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) {
                                if (borderInfoCompute[bd_r1 + "_" + bd_c] == null) {
                                    borderInfoCompute[bd_r1 + "_" + bd_c] = {};
                                }

                                borderInfoCompute[bd_r1 + "_" + bd_c].t = {"color": borderColor, "style": borderStyle};

                                let bd_r_top = bd_r1 - 1;

                                if (bd_r_top >= 0 && borderInfoCompute[bd_r_top + "_" + bd_c]) {
                                    if (data[bd_r_top] != null && getObjType(data[bd_r_top][bd_c]) == "object" && data[bd_r_top][bd_c].mc != null) {
                                        let cell_top = data[bd_r_top][bd_c];

                                        let mc = cfg["merge"][cell_top.mc.r + "_" + cell_top.mc.c];

                                        if (mc.r + mc.rs - 1 == bd_r_top) {
                                            borderInfoCompute[bd_r_top + "_" + bd_c].b = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                        }
                                    } else {
                                        borderInfoCompute[bd_r_top + "_" + bd_c].b = {
                                            "color": borderColor,
                                            "style": borderStyle
                                        };
                                    }
                                }

                                let mc = cfg["merge"] || {};
                                for (const key in mc) {
                                    let {c, r, cs, rs} = mc[key];
                                    if (bd_r1 <= r + rs - 1 && bd_r1 > r && bd_c >= c && bd_c <= c + cs - 1) {
                                        borderInfoCompute[bd_r1 + "_" + bd_c].t = null;
                                    }
                                }
                            }
                        } else if (borderType == "border-bottom") {
                            if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r2] != null) {
                                continue;
                            }

                            for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) {
                                if (borderInfoCompute[bd_r2 + "_" + bd_c] == null) {
                                    borderInfoCompute[bd_r2 + "_" + bd_c] = {};
                                }

                                borderInfoCompute[bd_r2 + "_" + bd_c].b = {"color": borderColor, "style": borderStyle};

                                let bd_r_bottom = bd_r2 + 1;

                                if (bd_r_bottom < data.length && borderInfoCompute[bd_r_bottom + "_" + bd_c]) {
                                    if (data[bd_r_bottom] != null && getObjType(data[bd_r_bottom][bd_c]) == "object" && data[bd_r_bottom][bd_c].mc != null) {
                                        let cell_bottom = data[bd_r_bottom][bd_c];

                                        let mc = cfg["merge"][cell_bottom.mc.r + "_" + cell_bottom.mc.c];

                                        if (mc.r == bd_r_bottom) {
                                            borderInfoCompute[bd_r_bottom + "_" + bd_c].t = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                        }
                                    } else {
                                        borderInfoCompute[bd_r_bottom + "_" + bd_c].t = {
                                            "color": borderColor,
                                            "style": borderStyle
                                        };
                                    }
                                }

                                let mc = cfg["merge"] || {};
                                for (const key in mc) {
                                    let {c, r, cs, rs} = mc[key];
                                    if (bd_r2 < r + rs - 1 && bd_r2 >= r && bd_c >= c && bd_c <= c + cs - 1) {
                                        borderInfoCompute[bd_r2 + "_" + bd_c].b = null;
                                    }
                                }
                            }
                        } else if (borderType == "border-all") {
                            for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) {
                                if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
                                    continue;
                                }

                                for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) {
                                    if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) {
                                        let cell = data[bd_r][bd_c];

                                        let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c];
                                        if (mc == undefined || mc == null) {
                                            continue
                                        }
                                        ;
                                        if (mc.r == bd_r) {
                                            if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                borderInfoCompute[bd_r + "_" + bd_c] = {};
                                            }

                                            borderInfoCompute[bd_r + "_" + bd_c].t = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                        }

                                        if (mc.r + mc.rs - 1 == bd_r) {
                                            if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                borderInfoCompute[bd_r + "_" + bd_c] = {};
                                            }

                                            borderInfoCompute[bd_r + "_" + bd_c].b = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                        }

                                        if (mc.c == bd_c) {
                                            if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                borderInfoCompute[bd_r + "_" + bd_c] = {};
                                            }

                                            borderInfoCompute[bd_r + "_" + bd_c].l = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                        }

                                        if (mc.c + mc.cs - 1 == bd_c) {
                                            if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                borderInfoCompute[bd_r + "_" + bd_c] = {};
                                            }

                                            borderInfoCompute[bd_r + "_" + bd_c].r = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                        }
                                    } else {
                                        if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                            borderInfoCompute[bd_r + "_" + bd_c] = {};
                                        }

                                        borderInfoCompute[bd_r + "_" + bd_c].l = {
                                            "color": borderColor,
                                            "style": borderStyle
                                        };
                                        borderInfoCompute[bd_r + "_" + bd_c].r = {
                                            "color": borderColor,
                                            "style": borderStyle
                                        };
                                        borderInfoCompute[bd_r + "_" + bd_c].t = {
                                            "color": borderColor,
                                            "style": borderStyle
                                        };
                                        borderInfoCompute[bd_r + "_" + bd_c].b = {
                                            "color": borderColor,
                                            "style": borderStyle
                                        };
                                    }

                                    if (bd_r == bd_r1) {
                                        let bd_r_top = bd_r1 - 1;

                                        if (bd_r_top >= 0 && borderInfoCompute[bd_r_top + "_" + bd_c]) {
                                            if (data[bd_r_top] != null && getObjType(data[bd_r_top][bd_c]) == "object" && data[bd_r_top][bd_c].mc != null) {
                                                let cell_top = data[bd_r_top][bd_c];

                                                let mc = cfg["merge"][cell_top.mc.r + "_" + cell_top.mc.c];

                                                if (mc.r + mc.rs - 1 == bd_r_top) {
                                                    borderInfoCompute[bd_r_top + "_" + bd_c].b = {
                                                        "color": borderColor,
                                                        "style": borderStyle
                                                    };
                                                }
                                            } else {
                                                borderInfoCompute[bd_r_top + "_" + bd_c].b = {
                                                    "color": borderColor,
                                                    "style": borderStyle
                                                };
                                            }
                                        }
                                    }

                                    if (bd_r == bd_r2) {
                                        let bd_r_bottom = bd_r2 + 1;

                                        if (bd_r_bottom < data.length && borderInfoCompute[bd_r_bottom + "_" + bd_c]) {
                                            if (data[bd_r_bottom] != null && getObjType(data[bd_r_bottom][bd_c]) == "object" && data[bd_r_bottom][bd_c].mc != null) {
                                                let cell_bottom = data[bd_r_bottom][bd_c];

                                                let mc = cfg["merge"][cell_bottom.mc.r + "_" + cell_bottom.mc.c];

                                                if (mc.r == bd_r_bottom) {
                                                    borderInfoCompute[bd_r_bottom + "_" + bd_c].t = {
                                                        "color": borderColor,
                                                        "style": borderStyle
                                                    };
                                                }
                                            } else {
                                                borderInfoCompute[bd_r_bottom + "_" + bd_c].t = {
                                                    "color": borderColor,
                                                    "style": borderStyle
                                                };
                                            }
                                        }
                                    }

                                    if (bd_c == bd_c1) {
                                        let bd_c_left = bd_c1 - 1;

                                        if (bd_c_left >= 0 && borderInfoCompute[bd_r + "_" + bd_c_left]) {
                                            if (data[bd_r] != null && getObjType(data[bd_r][bd_c_left]) == "object" && data[bd_r][bd_c_left].mc != null) {
                                                let cell_left = data[bd_r][bd_c_left];

                                                let mc = cfg["merge"][cell_left.mc.r + "_" + cell_left.mc.c];

                                                if (mc.c + mc.cs - 1 == bd_c_left) {
                                                    borderInfoCompute[bd_r + "_" + bd_c_left].r = {
                                                        "color": borderColor,
                                                        "style": borderStyle
                                                    };
                                                }
                                            } else {
                                                borderInfoCompute[bd_r + "_" + bd_c_left].r = {
                                                    "color": borderColor,
                                                    "style": borderStyle
                                                };
                                            }
                                        }
                                    }

                                    if (bd_c == bd_c2) {
                                        let bd_c_right = bd_c2 + 1;

                                        if (bd_c_right < data[0].length && borderInfoCompute[bd_r + "_" + bd_c_right]) {
                                            if (data[bd_r] != null && getObjType(data[bd_r][bd_c_right]) == "object" && data[bd_r][bd_c_right].mc != null) {
                                                let cell_right = data[bd_r][bd_c_right];

                                                let mc = cfg["merge"][cell_right.mc.r + "_" + cell_right.mc.c];

                                                if (mc.c == bd_c_right) {
                                                    borderInfoCompute[bd_r + "_" + bd_c_right].l = {
                                                        "color": borderColor,
                                                        "style": borderStyle
                                                    };
                                                }
                                            } else {
                                                borderInfoCompute[bd_r + "_" + bd_c_right].l = {
                                                    "color": borderColor,
                                                    "style": borderStyle
                                                };
                                            }
                                        }
                                    }
                                }
                            }
                        } else if (borderType == "border-outside") {
                            for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) {
                                if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
                                    continue;
                                }

                                for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) {
                                    if (!(bd_r == bd_r1 || bd_r == bd_r2 || bd_c == bd_c1 || bd_c == bd_c2)) {
                                        continue;
                                    }

                                    if (bd_r == bd_r1) {
                                        if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                            borderInfoCompute[bd_r + "_" + bd_c] = {};
                                        }

                                        borderInfoCompute[bd_r + "_" + bd_c].t = {
                                            "color": borderColor,
                                            "style": borderStyle
                                        };

                                        let bd_r_top = bd_r1 - 1;

                                        if (bd_r_top >= 0 && borderInfoCompute[bd_r_top + "_" + bd_c]) {
                                            if (data[bd_r_top] != null && getObjType(data[bd_r_top][bd_c]) == "object" && data[bd_r_top][bd_c].mc != null) {
                                                let cell_top = data[bd_r_top][bd_c];

                                                let mc = cfg["merge"][cell_top.mc.r + "_" + cell_top.mc.c];

                                                if (mc.r + mc.rs - 1 == bd_r_top) {
                                                    borderInfoCompute[bd_r_top + "_" + bd_c].b = {
                                                        "color": borderColor,
                                                        "style": borderStyle
                                                    };
                                                }
                                            } else {
                                                borderInfoCompute[bd_r_top + "_" + bd_c].b = {
                                                    "color": borderColor,
                                                    "style": borderStyle
                                                };
                                            }
                                        }
                                    }

                                    if (bd_r == bd_r2) {
                                        if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                            borderInfoCompute[bd_r + "_" + bd_c] = {};
                                        }

                                        borderInfoCompute[bd_r + "_" + bd_c].b = {
                                            "color": borderColor,
                                            "style": borderStyle
                                        };

                                        let bd_r_bottom = bd_r2 + 1;

                                        if (bd_r_bottom < data.length && borderInfoCompute[bd_r_bottom + "_" + bd_c]) {
                                            if (data[bd_r_bottom] != null && getObjType(data[bd_r_bottom][bd_c]) == "object" && data[bd_r_bottom][bd_c].mc != null) {
                                                let cell_bottom = data[bd_r_bottom][bd_c];

                                                let mc = cfg["merge"][cell_bottom.mc.r + "_" + cell_bottom.mc.c];

                                                if (mc.r == bd_r_bottom) {
                                                    borderInfoCompute[bd_r_bottom + "_" + bd_c].t = {
                                                        "color": borderColor,
                                                        "style": borderStyle
                                                    };
                                                }
                                            } else {
                                                borderInfoCompute[bd_r_bottom + "_" + bd_c].t = {
                                                    "color": borderColor,
                                                    "style": borderStyle
                                                };
                                            }
                                        }
                                    }

                                    if (bd_c == bd_c1) {
                                        if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                            borderInfoCompute[bd_r + "_" + bd_c] = {};
                                        }

                                        borderInfoCompute[bd_r + "_" + bd_c].l = {
                                            "color": borderColor,
                                            "style": borderStyle
                                        };

                                        let bd_c_left = bd_c1 - 1;

                                        if (bd_c_left >= 0 && borderInfoCompute[bd_r + "_" + bd_c_left]) {
                                            if (data[bd_r] != null && getObjType(data[bd_r][bd_c_left]) == "object" && data[bd_r][bd_c_left].mc != null) {
                                                let cell_left = data[bd_r][bd_c_left];

                                                let mc = cfg["merge"][cell_left.mc.r + "_" + cell_left.mc.c];

                                                if (mc.c + mc.cs - 1 == bd_c_left) {
                                                    borderInfoCompute[bd_r + "_" + bd_c_left].r = {
                                                        "color": borderColor,
                                                        "style": borderStyle
                                                    };
                                                }
                                            } else {
                                                borderInfoCompute[bd_r + "_" + bd_c_left].r = {
                                                    "color": borderColor,
                                                    "style": borderStyle
                                                };
                                            }
                                        }
                                    }

                                    if (bd_c == bd_c2) {
                                        if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                            borderInfoCompute[bd_r + "_" + bd_c] = {};
                                        }

                                        borderInfoCompute[bd_r + "_" + bd_c].r = {
                                            "color": borderColor,
                                            "style": borderStyle
                                        };

                                        let bd_c_right = bd_c2 + 1;

                                        if (bd_c_right < data[0].length && borderInfoCompute[bd_r + "_" + bd_c_right]) {
                                            if (data[bd_r] != null && getObjType(data[bd_r][bd_c_right]) == "object" && data[bd_r][bd_c_right].mc != null) {
                                                let cell_right = data[bd_r][bd_c_right];

                                                let mc = cfg["merge"][cell_right.mc.r + "_" + cell_right.mc.c];

                                                if (mc.c == bd_c_right) {
                                                    borderInfoCompute[bd_r + "_" + bd_c_right].l = {
                                                        "color": borderColor,
                                                        "style": borderStyle
                                                    };
                                                }
                                            } else {
                                                borderInfoCompute[bd_r + "_" + bd_c_right].l = {
                                                    "color": borderColor,
                                                    "style": borderStyle
                                                };
                                            }
                                        }
                                    }
                                }
                            }
                        } else if (borderType == "border-inside") {
                            for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) {
                                if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
                                    continue;
                                }

                                for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) {
                                    if (bd_r == bd_r1 && bd_c == bd_c1) {
                                        if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) {

                                        } else {
                                            if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                borderInfoCompute[bd_r + "_" + bd_c] = {};
                                            }

                                            borderInfoCompute[bd_r + "_" + bd_c].r = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                            borderInfoCompute[bd_r + "_" + bd_c].b = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                        }
                                    } else if (bd_r == bd_r2 && bd_c == bd_c1) {
                                        if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) {

                                        } else {
                                            if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                borderInfoCompute[bd_r + "_" + bd_c] = {};
                                            }

                                            borderInfoCompute[bd_r + "_" + bd_c].r = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                            borderInfoCompute[bd_r + "_" + bd_c].t = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                        }
                                    } else if (bd_r == bd_r1 && bd_c == bd_c2) {
                                        if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) {

                                        } else {
                                            if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                borderInfoCompute[bd_r + "_" + bd_c] = {};
                                            }

                                            borderInfoCompute[bd_r + "_" + bd_c].l = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                            borderInfoCompute[bd_r + "_" + bd_c].b = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                        }
                                    } else if (bd_r == bd_r2 && bd_c == bd_c2) {
                                        if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) {

                                        } else {
                                            if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                borderInfoCompute[bd_r + "_" + bd_c] = {};
                                            }

                                            borderInfoCompute[bd_r + "_" + bd_c].l = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                            borderInfoCompute[bd_r + "_" + bd_c].t = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                        }
                                    } else if (bd_r == bd_r1) {
                                        if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) {
                                            let cell = data[bd_r][bd_c];

                                            let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c];

                                            if (mc.c == bd_c) {
                                                if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                    borderInfoCompute[bd_r + "_" + bd_c] = {};
                                                }

                                                borderInfoCompute[bd_r + "_" + bd_c].l = {
                                                    "color": borderColor,
                                                    "style": borderStyle
                                                };
                                            } else if (mc.c + mc.cs - 1 == bd_c) {
                                                if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                    borderInfoCompute[bd_r + "_" + bd_c] = {};
                                                }

                                                borderInfoCompute[bd_r + "_" + bd_c].r = {
                                                    "color": borderColor,
                                                    "style": borderStyle
                                                };
                                            }
                                        } else {
                                            if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                borderInfoCompute[bd_r + "_" + bd_c] = {};
                                            }

                                            borderInfoCompute[bd_r + "_" + bd_c].l = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                            borderInfoCompute[bd_r + "_" + bd_c].r = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                            borderInfoCompute[bd_r + "_" + bd_c].b = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                        }
                                    } else if (bd_r == bd_r2) {
                                        if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) {
                                            let cell = data[bd_r][bd_c];

                                            let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c];

                                            if (mc.c == bd_c) {
                                                if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                    borderInfoCompute[bd_r + "_" + bd_c] = {};
                                                }

                                                borderInfoCompute[bd_r + "_" + bd_c].l = {
                                                    "color": borderColor,
                                                    "style": borderStyle
                                                };
                                            } else if (mc.c + mc.cs - 1 == bd_c) {
                                                if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                    borderInfoCompute[bd_r + "_" + bd_c] = {};
                                                }

                                                borderInfoCompute[bd_r + "_" + bd_c].r = {
                                                    "color": borderColor,
                                                    "style": borderStyle
                                                };
                                            }
                                        } else {
                                            if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                borderInfoCompute[bd_r + "_" + bd_c] = {};
                                            }

                                            borderInfoCompute[bd_r + "_" + bd_c].l = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                            borderInfoCompute[bd_r + "_" + bd_c].r = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                            borderInfoCompute[bd_r + "_" + bd_c].t = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                        }
                                    } else if (bd_c == bd_c1) {
                                        if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) {
                                            let cell = data[bd_r][bd_c];

                                            let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c];

                                            if (mc.r == bd_r) {
                                                if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                    borderInfoCompute[bd_r + "_" + bd_c] = {};
                                                }

                                                borderInfoCompute[bd_r + "_" + bd_c].t = {
                                                    "color": borderColor,
                                                    "style": borderStyle
                                                };
                                            } else if (mc.r + mc.rs - 1 == bd_r) {
                                                if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                    borderInfoCompute[bd_r + "_" + bd_c] = {};
                                                }

                                                borderInfoCompute[bd_r + "_" + bd_c].b = {
                                                    "color": borderColor,
                                                    "style": borderStyle
                                                };
                                            }
                                        } else {
                                            if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                borderInfoCompute[bd_r + "_" + bd_c] = {};
                                            }

                                            borderInfoCompute[bd_r + "_" + bd_c].r = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                            borderInfoCompute[bd_r + "_" + bd_c].t = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                            borderInfoCompute[bd_r + "_" + bd_c].b = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                        }
                                    } else if (bd_c == bd_c2) {
                                        if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) {
                                            let cell = data[bd_r][bd_c];

                                            let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c];

                                            if (mc.r == bd_r) {
                                                if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                    borderInfoCompute[bd_r + "_" + bd_c] = {};
                                                }

                                                borderInfoCompute[bd_r + "_" + bd_c].t = {
                                                    "color": borderColor,
                                                    "style": borderStyle
                                                };
                                            } else if (mc.r + mc.rs - 1 == bd_r) {
                                                if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                    borderInfoCompute[bd_r + "_" + bd_c] = {};
                                                }

                                                borderInfoCompute[bd_r + "_" + bd_c].b = {
                                                    "color": borderColor,
                                                    "style": borderStyle
                                                };
                                            }
                                        } else {
                                            if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                borderInfoCompute[bd_r + "_" + bd_c] = {};
                                            }

                                            borderInfoCompute[bd_r + "_" + bd_c].l = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                            borderInfoCompute[bd_r + "_" + bd_c].t = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                            borderInfoCompute[bd_r + "_" + bd_c].b = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                        }
                                    } else {
                                        if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) {
                                            let cell = data[bd_r][bd_c];

                                            let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c];

                                            if (mc.r == bd_r) {
                                                if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                    borderInfoCompute[bd_r + "_" + bd_c] = {};
                                                }

                                                borderInfoCompute[bd_r + "_" + bd_c].t = {
                                                    "color": borderColor,
                                                    "style": borderStyle
                                                };
                                            } else if (mc.r + mc.rs - 1 == bd_r) {
                                                if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                    borderInfoCompute[bd_r + "_" + bd_c] = {};
                                                }

                                                borderInfoCompute[bd_r + "_" + bd_c].b = {
                                                    "color": borderColor,
                                                    "style": borderStyle
                                                };
                                            }

                                            if (mc.c == bd_c) {
                                                if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                    borderInfoCompute[bd_r + "_" + bd_c] = {};
                                                }

                                                borderInfoCompute[bd_r + "_" + bd_c].l = {
                                                    "color": borderColor,
                                                    "style": borderStyle
                                                };
                                            } else if (mc.c + mc.cs - 1 == bd_c) {
                                                if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                    borderInfoCompute[bd_r + "_" + bd_c] = {};
                                                }

                                                borderInfoCompute[bd_r + "_" + bd_c].r = {
                                                    "color": borderColor,
                                                    "style": borderStyle
                                                };
                                            }
                                        } else {
                                            if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                borderInfoCompute[bd_r + "_" + bd_c] = {};
                                            }

                                            borderInfoCompute[bd_r + "_" + bd_c].l = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                            borderInfoCompute[bd_r + "_" + bd_c].r = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                            borderInfoCompute[bd_r + "_" + bd_c].t = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                            borderInfoCompute[bd_r + "_" + bd_c].b = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                        }
                                    }
                                }
                            }
                        } else if (borderType == "border-horizontal") {
                            for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) {
                                if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
                                    continue;
                                }

                                for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) {
                                    if (bd_r == bd_r1) {
                                        if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) {

                                        } else {
                                            if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                borderInfoCompute[bd_r + "_" + bd_c] = {};
                                            }

                                            borderInfoCompute[bd_r + "_" + bd_c].b = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                        }
                                    } else if (bd_r == bd_r2) {
                                        if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) {

                                        } else {
                                            if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                borderInfoCompute[bd_r + "_" + bd_c] = {};
                                            }

                                            borderInfoCompute[bd_r + "_" + bd_c].t = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                        }
                                    } else {
                                        if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) {
                                            let cell = data[bd_r][bd_c];

                                            let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c];

                                            if (mc.r == bd_r) {
                                                if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                    borderInfoCompute[bd_r + "_" + bd_c] = {};
                                                }

                                                borderInfoCompute[bd_r + "_" + bd_c].t = {
                                                    "color": borderColor,
                                                    "style": borderStyle
                                                };
                                            } else if (mc.r + mc.rs - 1 == bd_r) {
                                                if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                    borderInfoCompute[bd_r + "_" + bd_c] = {};
                                                }

                                                borderInfoCompute[bd_r + "_" + bd_c].b = {
                                                    "color": borderColor,
                                                    "style": borderStyle
                                                };
                                            }
                                        } else {
                                            if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                borderInfoCompute[bd_r + "_" + bd_c] = {};
                                            }

                                            borderInfoCompute[bd_r + "_" + bd_c].t = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                            borderInfoCompute[bd_r + "_" + bd_c].b = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                        }
                                    }
                                }
                            }
                        } else if (borderType == "border-vertical") {
                            for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) {
                                if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
                                    continue;
                                }

                                for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) {
                                    if (bd_c == bd_c1) {
                                        if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) {

                                        } else {
                                            if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                borderInfoCompute[bd_r + "_" + bd_c] = {};
                                            }

                                            borderInfoCompute[bd_r + "_" + bd_c].r = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                        }
                                    } else if (bd_c == bd_c2) {
                                        if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) {

                                        } else {
                                            if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                borderInfoCompute[bd_r + "_" + bd_c] = {};
                                            }

                                            borderInfoCompute[bd_r + "_" + bd_c].l = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                        }
                                    } else {
                                        if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) {
                                            let cell = data[bd_r][bd_c];

                                            let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c] || {};

                                            if (mc.c == bd_c) {
                                                if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                    borderInfoCompute[bd_r + "_" + bd_c] = {};
                                                }

                                                borderInfoCompute[bd_r + "_" + bd_c].l = {
                                                    "color": borderColor,
                                                    "style": borderStyle
                                                };
                                            } else if (mc.c + mc.cs - 1 == bd_c) {
                                                if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                    borderInfoCompute[bd_r + "_" + bd_c] = {};
                                                }

                                                borderInfoCompute[bd_r + "_" + bd_c].r = {
                                                    "color": borderColor,
                                                    "style": borderStyle
                                                };
                                            }
                                        } else {
                                            if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                                                borderInfoCompute[bd_r + "_" + bd_c] = {};
                                            }

                                            borderInfoCompute[bd_r + "_" + bd_c].l = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                            borderInfoCompute[bd_r + "_" + bd_c].r = {
                                                "color": borderColor,
                                                "style": borderStyle
                                            };
                                        }
                                    }
                                }
                            }
                        } else if (borderType == "border-none") {
                            for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) {
                                if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
                                    continue;
                                }

                                for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) {
                                    if (borderInfoCompute[bd_r + "_" + bd_c] != null) {
                                        delete borderInfoCompute[bd_r + "_" + bd_c];
                                    }

                                    if (bd_r == bd_r1) {
                                        let bd_r_top = bd_r1 - 1;

                                        if (bd_r_top >= 0 && borderInfoCompute[bd_r_top + "_" + bd_c]) {
                                            delete borderInfoCompute[bd_r_top + "_" + bd_c].b;
                                        }
                                    }

                                    if (bd_r == bd_r2) {
                                        let bd_r_bottom = bd_r2 + 1;

                                        if (bd_r_bottom < data.length && borderInfoCompute[bd_r_bottom + "_" + bd_c]) {
                                            delete borderInfoCompute[bd_r_bottom + "_" + bd_c].t;
                                        }
                                    }

                                    if (bd_c == bd_c1) {
                                        let bd_c_left = bd_c1 - 1;

                                        if (bd_c_left >= 0 && borderInfoCompute[bd_r + "_" + bd_c_left]) {
                                            delete borderInfoCompute[bd_r + "_" + bd_c_left].r;
                                        }
                                    }

                                    if (bd_c == bd_c2) {
                                        let bd_c_right = bd_c2 + 1;

                                        if (bd_c_right < data[0].length && borderInfoCompute[bd_r + "_" + bd_c_right]) {
                                            delete borderInfoCompute[bd_r + "_" + bd_c_right].l;
                                        }
                                    }
                                }
                            }
                        }
                    }
                } else if (rangeType == "cell") {
                    let value = borderInfo[i].value;

                    let bd_r = value.row_index, bd_c = value.col_index;

                    if (bd_r < dataset_row_st || bd_r > dataset_row_ed || bd_c < dataset_col_st || bd_c > dataset_col_ed) {
                        continue;
                    }

                    if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
                        continue;
                    }

                    if (value.l != null || value.r != null || value.t != null || value.b != null) {
                        if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
                            borderInfoCompute[bd_r + "_" + bd_c] = {};
                        }

                        if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) {
                            let cell = data[bd_r][bd_c];
                            let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c] || {};

                            if (value.l != null && bd_c == mc.c) { //左边框
                                borderInfoCompute[bd_r + "_" + bd_c].l = {
                                    "color": value.l.color,
                                    "style": value.l.style
                                };

                                let bd_c_left = bd_c - 1;

                                if (bd_c_left >= 0 && borderInfoCompute[bd_r + "_" + bd_c_left]) {
                                    if (data[bd_r] != null && getObjType(data[bd_r][bd_c_left]) == "object" && data[bd_r][bd_c_left].mc != null) {
                                        let cell_left = data[bd_r][bd_c_left];

                                        let mc_l = cfg["merge"][cell_left.mc.r + "_" + cell_left.mc.c];

                                        if (mc_l.c + mc_l.cs - 1 == bd_c_left) {
                                            borderInfoCompute[bd_r + "_" + bd_c_left].r = {
                                                "color": value.l.color,
                                                "style": value.l.style
                                            };
                                        }
                                    } else {
                                        borderInfoCompute[bd_r + "_" + bd_c_left].r = {
                                            "color": value.l.color,
                                            "style": value.l.style
                                        };
                                    }
                                }
                            } else {
                                borderInfoCompute[bd_r + "_" + bd_c].l = null;
                            }

                            if (value.r != null && bd_c == mc.c + mc.cs - 1) { //右边框
                                borderInfoCompute[bd_r + "_" + bd_c].r = {
                                    "color": value.r.color,
                                    "style": value.r.style
                                };

                                let bd_c_right = bd_c + 1;

                                if (bd_c_right < data[0].length && borderInfoCompute[bd_r + "_" + bd_c_right]) {
                                    if (data[bd_r] != null && getObjType(data[bd_r][bd_c_right]) == "object" && data[bd_r][bd_c_right].mc != null) {
                                        let cell_right = data[bd_r][bd_c_right];

                                        let mc_r = cfg["merge"][cell_right.mc.r + "_" + cell_right.mc.c];

                                        if (mc_r.c == bd_c_right) {
                                            borderInfoCompute[bd_r + "_" + bd_c_right].l = {
                                                "color": value.r.color,
                                                "style": value.r.style
                                            };
                                        }
                                    } else {
                                        borderInfoCompute[bd_r + "_" + bd_c_right].l = {
                                            "color": value.r.color,
                                            "style": value.r.style
                                        };
                                    }
                                }
                            } else {
                                borderInfoCompute[bd_r + "_" + bd_c].r = null;
                            }

                            if (value.t != null && bd_r == mc.r) { //上边框
                                borderInfoCompute[bd_r + "_" + bd_c].t = {
                                    "color": value.t.color,
                                    "style": value.t.style
                                };

                                let bd_r_top = bd_r - 1;

                                if (bd_r_top >= 0 && borderInfoCompute[bd_r_top + "_" + bd_c]) {
                                    if (data[bd_r_top] != null && getObjType(data[bd_r_top][bd_c]) == "object" && data[bd_r_top][bd_c].mc != null) {
                                        let cell_top = data[bd_r_top][bd_c];

                                        let mc_t = cfg["merge"][cell_top.mc.r + "_" + cell_top.mc.c];

                                        if (mc_t.r + mc_t.rs - 1 == bd_r_top) {
                                            borderInfoCompute[bd_r_top + "_" + bd_c].b = {
                                                "color": value.t.color,
                                                "style": value.t.style
                                            };
                                        }
                                    } else {
                                        borderInfoCompute[bd_r_top + "_" + bd_c].b = {
                                            "color": value.t.color,
                                            "style": value.t.style
                                        };
                                    }
                                }
                            } else {
                                borderInfoCompute[bd_r + "_" + bd_c].t = null;
                            }

                            if (value.b != null && bd_r == mc.r + mc.rs - 1) { //下边框
                                borderInfoCompute[bd_r + "_" + bd_c].b = {
                                    "color": value.b.color,
                                    "style": value.b.style
                                };

                                let bd_r_bottom = bd_r + 1;

                                if (bd_r_bottom < data.length && borderInfoCompute[bd_r_bottom + "_" + bd_c]) {
                                    if (data[bd_r_bottom] != null && getObjType(data[bd_r_bottom][bd_c]) == "object" && data[bd_r_bottom][bd_c].mc != null) {
                                        let cell_bottom = data[bd_r_bottom][bd_c];

                                        let mc_b = cfg["merge"][cell_bottom.mc.r + "_" + cell_bottom.mc.c];

                                        if (mc_b.r == bd_r_bottom) {
                                            borderInfoCompute[bd_r_bottom + "_" + bd_c].t = {
                                                "color": value.b.color,
                                                "style": value.b.style
                                            };
                                        }
                                    } else {
                                        borderInfoCompute[bd_r_bottom + "_" + bd_c].t = {
                                            "color": value.b.color,
                                            "style": value.b.style
                                        };
                                    }
                                }
                            } else {
                                borderInfoCompute[bd_r + "_" + bd_c].b = null;
                            }
                        } else {
                            if (value.l != null) { //左边框
                                borderInfoCompute[bd_r + "_" + bd_c].l = {
                                    "color": value.l.color,
                                    "style": value.l.style
                                };

                                let bd_c_left = bd_c - 1;

                                if (bd_c_left >= 0 && borderInfoCompute[bd_r + "_" + bd_c_left]) {
                                    if (data[bd_r] != null && getObjType(data[bd_r][bd_c_left]) == "object" && data[bd_r][bd_c_left].mc != null) {
                                        let cell_left = data[bd_r][bd_c_left];

                                        let mc_l = cfg["merge"][cell_left.mc.r + "_" + cell_left.mc.c];

                                        if (mc_l.c + mc_l.cs - 1 == bd_c_left) {
                                            borderInfoCompute[bd_r + "_" + bd_c_left].r = {
                                                "color": value.l.color,
                                                "style": value.l.style
                                            };
                                        }
                                    } else {
                                        borderInfoCompute[bd_r + "_" + bd_c_left].r = {
                                            "color": value.l.color,
                                            "style": value.l.style
                                        };
                                    }
                                }
                            } else {
                                borderInfoCompute[bd_r + "_" + bd_c].l = null;
                            }

                            if (value.r != null) { //右边框
                                borderInfoCompute[bd_r + "_" + bd_c].r = {
                                    "color": value.r.color,
                                    "style": value.r.style
                                };

                                let bd_c_right = bd_c + 1;

                                if (bd_c_right < data[0].length && borderInfoCompute[bd_r + "_" + bd_c_right]) {
                                    if (data[bd_r] != null && getObjType(data[bd_r][bd_c_right]) == "object" && data[bd_r][bd_c_right].mc != null) {
                                        let cell_right = data[bd_r][bd_c_right];
                                        let mc_r = cfg["merge"][cell_right.mc.r + "_" + cell_right.mc.c];
                                        if (mc_r.c == bd_c_right) {
                                            borderInfoCompute[bd_r + "_" + bd_c_right].l = {
                                                "color": value.r.color,
                                                "style": value.r.style
                                            };
                                        }
                                    } else {
                                        borderInfoCompute[bd_r + "_" + bd_c_right].l = {
                                            "color": value.r.color,
                                            "style": value.r.style
                                        };
                                    }
                                }
                            } else {
                                borderInfoCompute[bd_r + "_" + bd_c].r = null;
                            }

                            if (value.t != null) { //上边框
                                borderInfoCompute[bd_r + "_" + bd_c].t = {
                                    "color": value.t.color,
                                    "style": value.t.style
                                };

                                let bd_r_top = bd_r - 1;

                                if (bd_r_top >= 0 && borderInfoCompute[bd_r_top + "_" + bd_c]) {
                                    if (data[bd_r_top] != null && getObjType(data[bd_r_top][bd_c]) == "object" && data[bd_r_top][bd_c].mc != null) {
                                        let cell_top = data[bd_r_top][bd_c];

                                        let mc_t = cfg["merge"][cell_top.mc.r + "_" + cell_top.mc.c];

                                        if (mc_t.r + mc_t.rs - 1 == bd_r_top) {
                                            borderInfoCompute[bd_r_top + "_" + bd_c].b = {
                                                "color": value.t.color,
                                                "style": value.t.style
                                            };
                                        }
                                    } else {
                                        borderInfoCompute[bd_r_top + "_" + bd_c].b = {
                                            "color": value.t.color,
                                            "style": value.t.style
                                        };
                                    }
                                }
                            } else {
                                borderInfoCompute[bd_r + "_" + bd_c].t = null;
                            }

                            if (value.b != null) { //下边框
                                borderInfoCompute[bd_r + "_" + bd_c].b = {
                                    "color": value.b.color,
                                    "style": value.b.style
                                };

                                let bd_r_bottom = bd_r + 1;

                                if (bd_r_bottom < data.length && borderInfoCompute[bd_r_bottom + "_" + bd_c]) {
                                    if (data[bd_r_bottom] != null && getObjType(data[bd_r_bottom][bd_c]) == "object" && data[bd_r_bottom][bd_c].mc != null) {
                                        let cell_bottom = data[bd_r_bottom][bd_c];

                                        let mc_b = cfg["merge"][cell_bottom.mc.r + "_" + cell_bottom.mc.c];

                                        if (mc_b.r == bd_r_bottom) {
                                            borderInfoCompute[bd_r_bottom + "_" + bd_c].t = {
                                                "color": value.b.color,
                                                "style": value.b.style
                                            };
                                        }
                                    } else {
                                        borderInfoCompute[bd_r_bottom + "_" + bd_c].t = {
                                            "color": value.b.color,
                                            "style": value.b.style
                                        };
                                    }
                                }
                            } else {
                                borderInfoCompute[bd_r + "_" + bd_c].b = null;
                            }
                        }
                    } else {
                        delete borderInfoCompute[bd_r + "_" + bd_c];
                    }
                }
            }
        }
        return borderInfoCompute;
    }
//获取数据类型
    var getObjType = function (obj) {
        let toString = Object.prototype.toString;

        let map = {
            '[object Boolean]': 'boolean',
            '[object Number]': 'number',
            '[object String]': 'string',
            '[object Function]': 'function',
            '[object Array]': 'array',
            '[object Date]': 'date',
            '[object RegExp]': 'regExp',
            '[object Undefined]': 'undefined',
            '[object Null]': 'null',
            '[object Object]': 'object'
        }
        return map[toString.call(obj)];
    }

    /**
     * 设置带样式的值
     * @param cellArr
     * @param worksheet
     */
    var setStyleAndValue = function (cellArr, worksheet) {


        if (!Array.isArray(cellArr)) return
        cellArr.forEach(function (row, rowid) {
            row.every(function (cell, columnid) {
                if (!cell) return true
                let fill = fillConvert(cell.bg)

                let font = fontConvert(
                    cell.ff,
                    cell.fc,
                    cell.bl,
                    cell.it,
                    cell.fs,
                    cell.cl,
                    cell.un
                )
                let alignment = alignmentConvert(cell.vt, cell.ht, cell.tb, cell.tr)
                let value = ''

                if (cell.f) {
                    value = {formula: cell.f, result: cell.v}
                } else if (!cell.v && cell.ct && cell.ct.s) {
                    // xls转为xlsx之后，内部存在不同的格式，都会进到富文本里，即值不存在与cell.v，而是存在于cell.ct.s之后
                    let richText = [];
                    let cts = cell.ct.s
                    for (let i = 0; i < cts.length; i++) {
                        let font = fontConvert(cts[i].ff, cts[i].fc, cts[i].bl, cts[i].it, cts[i].fs, cts[i].cl, cts[i].un)
                        //  let font=  worksheet.getCell("A1").font
                        let rt = {
                            text: cts[i].v,
                            // font: font
                        }

                        richText.push(rt)
                    }

                    value = {
                        richText: richText
                    };

                } else {
                    //设置值为数字格式
                    if (cell.v !== undefined && cell.v !== '') {
                        var v = +cell.v;
                        if (isNaN(v)) v = cell.v
                        value = v
                    }
                }
                //  style 填入到_value中可以实现填充色
                let letter = createCellPos(columnid)
                let target = worksheet.getCell(letter + (rowid + 1))

                for (const key in fill) {
                    target.fill = fill
                    break
                }
                target.font = font
                target.alignment = alignment
                target.value = value ? value : ""
                try {
                    //设置单元格格式
                    target.numFmt = cell.ct.fa;
                } catch (e) {
                    console.warn(e)
                }

                return true
            })
        })
    }
    /**
     * 计算获取图片的坐标
     * @param {number} num 坐标点的top,left值
     * @param {array} arr 所有的行、列的长度集合
     * @returns 满足exceljs的坐标值，需要计算图片在cell中的偏移量nativeOff。
     */
    var getImagePosition = function (num, arr) {
        for (let i = 0; i < arr.length; i++) {
            const item = arr[i]
            if (num < item) {
                //单元格大小
                const cell = i > 0 ? arr[i] - arr[i - 1] : item
                // 偏移量单位为Emu,所以单元格的宽高需要转换为Emu的单位，cellWidth = cellWidth*10000
                const cellInEmu = cell * 10000

                const rowOrCol = i > 0 ? (num - arr[i - 1]) / (arr[i] - arr[i - 1]) + i : num / item

                const native = Math.floor(rowOrCol)
                const nativeOff = parseInt(new Big(rowOrCol).minus(native).toNumber() * cellInEmu)
                return {rowOrCol, native, nativeOff}
            }
        }
    }

    function getptToPxRatioByDPI() {
        return 72 / 96;
    }

    function getRowHeightPixel(rowHeight) {
        var pix = Math.round(rowHeight / getptToPxRatioByDPI());
        return pix;
    }

    /**
     * 设置图片
     * @param images
     * @param worksheet
     * @param workbook
     */
    var setImages = function (table, worksheet, workbook) {
        // debugger
        let {
            images,
            visibledatacolumn,//所有行的位置
            visibledatarow //所有列的位置
        } = {...table}

        if (typeof images != "object") return;
        for (let key in images) {
            // console.log(images[key]);
            // "..."
            // 通过 base64  将图像添加到工作簿

            if (!images[key].src) {
                continue
            }


            const myBase64Image = images[key].src;
            // //位置
            const imagePosition = Spread.Layout.imagePositionConvert(images[key])


            // const tl = {col: images[key].default.left / 72, row: images[key].default.top / 19}
            // 大小
            //  const ext = {width: images[key].default.width, height: images[key].default.height}

            const tl = imagePosition.tl
            const ext = imagePosition.ext
            // 只有设置tl、br的图片可以被luckysheet识别并展示，设置ext宽高的不行
            // const col_st = getImagePosition(images[key].default.left, visibledatacolumn);
            // const row_st = getImagePosition(images[key].default.top, visibledatarow);
            // const w_ed = images[key].default.left + images[key].default.width;
            // const h_ed = images[key].default.top + images[key].default.height;
            // const col_ed = getImagePosition(w_ed, visibledatacolumn);
            // const row_ed = getImagePosition(h_ed, visibledatarow);
            const br = imagePosition.br

            const imageId = workbook.addImage({
                base64: myBase64Image,
                extension: 'png',
            });
            let c = {
                tl: imagePosition.tl,
                br: imagePosition.br,
                // ext: imagePosition.ext,
                //br: imagePosition.br,
                editAs: 'oneCell',
            }
            worksheet.addImage(imageId, c);

            // worksheet.addImage(imageId, {
            //     tl: tl,
            //     ext: ext,
            //     editAs: 'absolute'
            // });
        }
    }

    /**
     * 冻结行列
     * @param frozen
     * @param worksheet
     */
    var setFrozen = function (frozen = {}, worksheet) {
        switch (frozen.type) {
            // 冻结首行
            case 'row': {
                worksheet.views = [
                    {state: 'frozen', xSplit: 0, ySplit: 1}
                ];
                break
            }
            // 冻结首列
            case 'column': {
                worksheet.views = [
                    {state: 'frozen', xSplit: 1, ySplit: 0}
                ];
                break
            }
            // 冻结行列
            case 'both': {
                worksheet.views = [
                    {state: 'frozen', xSplit: 1, ySplit: 1}
                ];
                break
            }
            // 冻结行到选区
            case 'rangeRow': {
                let row = frozen.range.row_focus + 1
                worksheet.views = [
                    {state: 'frozen', xSplit: 0, ySplit: row}
                ];
                break
            }
            // 冻结列到选区
            case 'rangeColumn': {
                let column = frozen.range.column_focus + 1
                worksheet.views = [
                    {state: 'frozen', xSplit: column, ySplit: 0}
                ];
                break
            }
            // 冻结行列到选区
            case 'rangeBoth': {
                let row = frozen.range.row_focus + 1
                let column = frozen.range.column_focus + 1
                worksheet.views = [
                    {state: 'frozen', xSplit: column, ySplit: row}
                ];
            }

        }

    }

    /**
     * 行隐藏
     * @param rowhidden
     * @param worksheet
     */
    var setRowHidden = function (rowhidden = {}, worksheet) {
        for (const key in rowhidden) {
            //如果当前行没有内容则隐藏不生效
            const row = worksheet.getRow(parseInt(key) + 1)
            row.hidden = true;
        }
    }

    /**
     * 列隐藏
     * @param colhidden
     * @param worksheet
     */
    var setColHidden = function (colhidden = {}, worksheet) {
        for (const key in colhidden) {
            const column = worksheet.getColumn(parseInt(key) + 1)
            column.hidden = true;
        }
    }

    /**
     * 自动筛选器
     * @param filter
     * @param worksheet
     */
    var setFilter = function (filter = {}, worksheet) {
        if (Object.keys(filter).length === 0) return
        const from = {
            row: filter.row[0] + 1,
            column: filter.column[0] + 1
        }

        const to = {
            row: filter.row[1] + 1,
            column: filter.column[1] + 1
        }

        worksheet.autoFilter = {
            from: from,
            to: to
        }

    }

    var fillConvert = function (bg) {
        if (!bg) {
            return {}
        }
        // const bgc = bg.replace('#', '')
        let fill = {
            type: 'pattern',
            pattern: 'solid',
            fgColor: {argb: bg.startsWith("#") ? bg.replace('#', '') : colorRGBtoHex(bg).replace("#", "")},
        }
        return fill;
    }

    var fontConvert = function (
        ff = 0,
        fc = '#000000',
        bl = 0,
        it = 0,
        fs = 11,
        cl = 0,
        ul = 0
    ) {
        // luckysheet：ff(样式), fc(颜色), bl(粗体), it(斜体), fs(大小), cl(删除线), ul(下划线)
        const luckyToExcel = {
            0: '微软雅黑',
            1: '宋体',
            2: '黑体',
            3: '楷体',
            4: '仿宋',
            5: '新宋体',
            6: '华文新魏',
            7: '华文行楷',
            8: '华文隶书',
            9: 'Arial',
            10: 'Times New Roman ',
            11: 'Tahoma ',
            12: 'Verdana',
            num2bl: function (num) {
                return num !== 0
            }
        }

        // 出现Bug，导入的时候ff为luckyToExcel的val   typeof ff === 'number' ? luckyToExcel[ff] : ff,
        let font = {
            //   name: "宋体",
            //  family: 1,
            name: '等线', // 字体名称
            family: 3, // 字体族
            size: fs,
            charset: 134,
            scheme: "minor",
            color: {argb: fc.startsWith("#") ? fc.replace('#', '') : colorRGBtoHex(fc).replace("#", "")},
            bold: luckyToExcel.num2bl(bl),
            italic: luckyToExcel.num2bl(it),
            underline: luckyToExcel.num2bl(ul),
            strike: luckyToExcel.num2bl(cl)
        }

        return font
    }

    var alignmentConvert = function (
        vt = 'default',
        ht = 'default',
        tb = 'default',
        tr = 'default'
    ) {
        // luckysheet:vt(垂直), ht(水平), tb(换行), tr(旋转)
        const luckyToExcel = {
            vertical: {
                0: 'middle',
                1: 'top',
                2: 'bottom',
                default: 'middle'
            },
            horizontal: {
                0: 'center',
                1: 'left',
                2: 'right',
                default: 'center'
            },
            wrapText: {
                0: false,
                1: false,
                2: true,
                default: false
            },
            textRotation: {
                0: 0,
                1: 45,
                2: -45,
                3: 'vertical',
                4: 90,
                5: -90,
                default: 0
            }
        }

        let alignment = {
            vertical: luckyToExcel.vertical[vt],
            horizontal: luckyToExcel.horizontal[ht],
            wrapText: luckyToExcel.wrapText[tb],
            textRotation: luckyToExcel.textRotation[tr]
        }
        return alignment
    }

    var borderConvert = function (borderType, style = 1, color = '#000') {
        // 对应luckysheet的config中borderinfo的的参数
        if (!borderType) {
            return {}
        }
        const luckyToExcel = {
            type: {
                'border-all': 'all',
                'border-top': 'top',
                'border-right': 'right',
                'border-bottom': 'bottom',
                'border-left': 'left',
                'border-outside': 'outside',
                'border-inside': 'inside',
                'border-horizontal': 'horizontal',
                'border-vertical': 'vertical',
                'border-none': 'none',
            },
            style: {
                0: 'none',
                1: 'thin',
                2: 'hair',
                3: 'dotted',
                4: 'dashDot', // 'Dashed',
                5: 'dashDot',
                6: 'dashDotDot',
                7: 'double',
                8: 'medium',
                9: 'mediumDashed',
                10: 'mediumDashDot',
                11: 'mediumDashDotDot',
                12: 'slantDashDot',
                13: 'thick'
            }
        }
        let border = {}
        border[luckyToExcel.type[borderType]] = {
            style: luckyToExcel.style[style],
            color: {argb: color.replace('#', '')}
        }
        return border
    }

    function addborderToCell(borders, row_index, col_index) {
        let border = {}
        const luckyExcel = {
            type: {
                l: 'left',
                r: 'right',
                b: 'bottom',
                t: 'top'
            },
            style: {
                0: 'none',
                1: 'thin',
                2: 'hair',
                3: 'dotted',
                4: 'dashDot', // 'Dashed',
                5: 'dashDot',
                6: 'dashDotDot',
                7: 'double',
                8: 'medium',
                9: 'mediumDashed',
                10: 'mediumDashDot',
                11: 'mediumDashDotDot',
                12: 'slantDashDot',
                13: 'thick'
            }
        }

        for (const bor in borders) {

            if (borders[bor].color.indexOf('rgb') === -1) {
                border[luckyExcel.type[bor]] = {
                    style: luckyExcel.style[borders[bor].style],
                    color: {argb: borders[bor].color.replace('#', '')}
                }
            } else {
                border[luckyExcel.type[bor]] = {
                    style: luckyExcel.style[borders[bor].style],
                    color: {argb: borders[bor].color}
                }
            }
        }

        return border
    }

    function createCellPos(n) {
        let ordA = 'A'.charCodeAt(0)

        let ordZ = 'Z'.charCodeAt(0)
        let len = ordZ - ordA + 1
        let s = ''
        while (n >= 0) {
            s = String.fromCharCode((n % len) + ordA) + s

            n = Math.floor(n / len) - 1
        }
        return s
    }

//rgb(255,255,255)转16进制 #ffffff
    function colorRGBtoHex(color) {
        color = color.replace("rgb", "").replace("(", "").replace(")", "")
        var rgb = color.split(',');
        var r = parseInt(rgb[0]);
        var g = parseInt(rgb[1]);
        var b = parseInt(rgb[2]);
        return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
    }

    luckyexport.exportExcelFront = exportExcelFront

    luckyexport.getBorderInfo = getBorderInfo
})();



